package level.editor.main;

import java.awt.BorderLayout;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import level.editor.command.Command;
import level.editor.mediator.Module;
import level.editor.window.View;
import level.editor.window.Window;

/*
 * Handles command creation for the LevelModule. Acts as the
 * listener/interpreter for input on the level editor proper. The commands are
 * not fully formed, and require ToolModule to complete the request.
 */

public class LevelView extends JPanel implements View
{
	private Module module;
	private LevelOutput output;

	public LevelView()
	{
		super();
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		setBorder(BorderFactory.createTitledBorder("*New Level.xml"));
		output = new LevelOutput(this);
		output.addMouseListener(output);
		JScrollPane outputPanel = new JScrollPane(output);
		outputPanel.getVerticalScrollBar().addAdjustmentListener(output);
		outputPanel.getHorizontalScrollBar().addAdjustmentListener(output);
		this.add(outputPanel);

		LevelHotkeys.createHotkeys(this);
	}

	public void init(Window window)
	{
		window.add(this, BorderLayout.CENTER);
	}
	
	@Override
	public void pushUpCommand(Command command)
	{
		module.pushUpCommand(command);
	}

	@Override
	public void pushDownCommand(Command command)
	{
		output.pushDownCommand(command);
	}

	@Override
	public void registerModule(Module module)
	{
		this.module = module;
	}

}
